<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Page principale</title>
	
  	<link rel="stylesheet" href="<c:url value="/resources/Styles/styles.css"/>"/>
	<script src="<c:url value="/resources/js/jquery-1.8.3.js"/>"></script>

  	<script>
	function validParticipation(id){
		$('#idApp').val(id);
		$('#ApplicationUserForm').attr('action', 'validParticipation');
		$('#ApplicationUserForm').submit();
	}

	function valider(id){

		$.ajax({
			type: "POST",
			url: "<c:url value="participer"/>",
			data: "id=" + id,
			success: function(response){
				// we have the response
				if(response == "success"){
					$('#infoOk').html('Votre participation est prise en compte');
					$('#infoKo').html('');
				}else{
					$('#infoOk').html('');
					$('#infoKo').html('Erreur : participation en cours');
				}
				window.location.href = "<c:url value="/user/showApps"/>";
			},
			error: function(e){
				
			}
		});
	}
	
</script>
  	
</head>
<body>

<form:form method="post" commandName="ApplicationUserForm" id="ApplicationUserForm">

<div align="center"><h3><spring:message code="index.listeApps"/></h3></div>

<div align="center"></div><br/>

<div>

<table id="tableView" align="center" border="1" width="700">

	<tr>
		<th>Logo</th>
		<th>Test</th>
		<th>Etat</th>
		<th>Heure</th>
	</tr>
	
	<c:forEach items="${listApplication}" var="application">
	
	<tr >

		<td width="25%">
			<a onclick="javascript:todo();">
				<img src= "<c:url value="/resources/img/participations/${application.image}" />" title="rechercher"/>
			</a>
		</td>

		<td width="40%">
		
			<c:choose>
      			<c:when test="${application.statutApplication == 1}">
					<a title="tester" id="tester" target="_blank" href="${application.lien}">${application.libelle}</a>
					<br/>Montant : ${application.montant} &euro;
      			</c:when>
      			<c:otherwise>
					${application.libelle}
      			</c:otherwise>
			</c:choose>      
		</td>
	
		<td width="15%">
			<c:choose>
      			<c:when test="${application.statutApplication == 1}">
					<div id="statutEnCours">
						${application.statutApplicationLib}
					</div>
					<a onclick="javascript:valider(${application.id})">
						<img src="<c:url value="/resources/img/valider.png"/>" title="valider">
					</a>
      			</c:when>
     			<c:when test="${application.statutApplication == 2}">
					<div id="statutParticipation">
						${application.statutApplicationLib}
						<a onclick="javascript:validParticipation(${application.id});">
							<img src= "<c:url value="/resources/img/validParticipation.png" />" title="validParticipation"/>
						</a>
					 	
					</div>
				</c:when>
     			<c:when test="${application.statutApplication == 3}">
					<div id="statutParticipation">
						${application.statutApplicationLib} 
					</div>
				</c:when>
      			<c:otherwise>
					<div id="statutTerminee">
						${application.statutApplicationLib}
					</div>
      			</c:otherwise>
			</c:choose>

		</td>
		
		<td width="20%">

			<c:choose>
      			<c:when test="${application.statutApplication != 4}">
      				${application.dateMajStr}
      			</c:when>
   			</c:choose>

		</td>
	
	</tr>
	</c:forEach>

</table>

</div>

<form:hidden path="idApp" id="idApp"/>

</form:form>
</body>
</html>